package cn.tedu.csmall520.cart.webapi.controller;


import cn.tedu.csmall520.cart.serivce.ICartService;
import cn.tedu.csmall520.commons.pojo.cart.dto.CartAddDTO;
import cn.tedu.csmall520.commons.restful.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/base/cart")
@Api(tags = "购物车管理模块")
public class CartController {

    @Autowired
    private ICartService cartService;

    @PostMapping("/add-new")
    @ApiOperation("新增购物车商品")
    public JsonResult addNew (CartAddDTO cartAddDTO){
        log.debug("开始处理新增购物车商品的请求");
        cartService.addNew(cartAddDTO);
        return JsonResult.ok("新增成功");
    }

    @PostMapping("/delete")
    @ApiOperation("删除购物车商品")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id",name="userId",example = "UU100"),
            @ApiImplicitParam(value = "商品编号",name="commodityCode",example = "PC100")
    })
    public JsonResult delete (String userId,String commodityCode){
        cartService.delete(userId, commodityCode);
        return JsonResult.ok("删除成功");
    }
}
